package com.relife.common.quartz;

import java.lang.reflect.Method;

import com.relife.common.utils.StringUtil;
import com.relife.core.spring.SpringContextUtil;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;



public class MisJob implements Job {
	private static Logger log = Logger.getLogger(MisJob.class);


	public void execute(JobExecutionContext context) throws JobExecutionException {
		CronTriggerMis cron = (CronTriggerMis) context.getTrigger();
		Object service = SpringContextUtil.getService(cron.getServerName());
		if (service == null) {
			log.error("找不到对应的Server【" + cron.getServerName() + "】");
		} else if (StringUtil.isEmpty(cron.getMethod())) {
			log.error("Server【" + cron.getServerName() + "】里面没有对应的方法[" + cron.getMethod() + "]");
		} else {
			try {
				Method method = service.getClass().getDeclaredMethod(cron.getMethod());
				method.invoke(service);

			} catch (Exception e) {
				log.error(StringUtil.exception2String(e));
			}
		}
		log.info(cron.getFullJobName());
	}

}
